package com.dingtalk.yuanhua_spring_project.service.impl;

import java.util.concurrent.atomic.AtomicReference;

public class AccessTokenCache {
    private final AtomicReference<String> accessToken = new AtomicReference<>();
    private long expirationTime;

    public String getAccessToken() {
        return accessToken.get();
    }

    public void setAccessToken(String accessToken, long timeout) {
        this.accessToken.set(accessToken);
        this.expirationTime = System.currentTimeMillis() + timeout * 1000;
    }

    public boolean isExpired() {
        return System.currentTimeMillis() >= expirationTime;
    }
}
